﻿using Neural;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Collections;

namespace NNTest
{
    
    
    /// <summary>
    ///This is a test class for ErrorManagerTest and is intended
    ///to contain all ErrorManagerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ErrorManagerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Report
        ///</summary>
        [TestMethod()]
        public void ReportTest()
        {
            ErrorManager target = new ErrorManager(); // TODO: Initialize to an appropriate value
            Assert.AreEqual(target.ErrorHistorySize, 0);

            target.AddCalculator("SSE", new Neural.Calculators.SSEErrorCalculator());
            Dictionary<string, double> actual = new Dictionary<string, double>();
            actual["Foo"] = 0.0;

            Dictionary<string, double> expected = new Dictionary<string, double>();
            expected["Foo"] = 1.0;

            target.AccumulateError(expected, actual);
            Assert.AreEqual(0.5, target.Report["SSE"], 0.0001);

            target.ClearErrors();
            Assert.AreEqual(0.0, target.Report["SSE"], 0.0001);
        }

        /// <summary>
        ///A test for LastErrors
        ///</summary>
        [TestMethod()]
        public void LastErrorsTest()
        {
            ErrorManager target = new ErrorManager(); // TODO: Initialize to an appropriate value
            Assert.AreEqual(target.ErrorHistorySize, 0);

            target.AddCalculator("SSE", new Neural.Calculators.SSEErrorCalculator());
            Dictionary<string, double> actual = new Dictionary<string, double>();
            actual["Foo"] = 0.0;

            Dictionary<string, double> expected = new Dictionary<string, double>();
            expected["Foo"] = 1.0;

            target.AccumulateError(expected, actual);
            target.ClearErrors();
            target.AccumulateError(expected, actual);
            Assert.AreEqual(0.5, target.LastErrors["SSE"], 0.0001);
        }

        /// <summary>
        ///A test for ErrorHistorySize
        ///</summary>
        [TestMethod()]
        public void ErrorHistorySizeTest()
        {
            ErrorManager target = new ErrorManager(); // TODO: Initialize to an appropriate value
            Assert.AreEqual(target.ErrorHistorySize, 0);

            target.AddCalculator("SSE", new Neural.Calculators.SSEErrorCalculator());
            Dictionary<string, double> actual = new Dictionary<string, double>();
            actual["Foo"] = 0.0;

            Dictionary<string, double> expected = new Dictionary<string, double>();
            expected["Foo"] = 1.0;

            target.AccumulateError(expected, actual);
            target.ClearErrors();
            target.AccumulateError(expected, actual);
            Assert.AreEqual(1, target.ErrorHistorySize);
        }

        /// <summary>
        ///A test for Count
        ///</summary>
        [TestMethod()]
        public void CountTest()
        {
            ErrorManager target = new ErrorManager(); // TODO: Initialize to an appropriate value
            Assert.AreEqual(target.Count, 0);

            target.AddCalculator("SSE", new Neural.Calculators.SSEErrorCalculator());
            Assert.AreEqual(target.Count, 1);
        }

        /// <summary>
        ///A test for ListCalculators
        ///</summary>
        [TestMethod()]
        public void ListCalculatorsTest()
        {
            ErrorManager target = new ErrorManager(); // TODO: Initialize to an appropriate value
            target.AddCalculator("Foo", new Neural.Calculators.SSEErrorCalculator());
            target.AddCalculator("SSE", new Neural.Calculators.SSEErrorCalculator());

            Assert.AreEqual(2, target.ListCalculators().Count);
            Assert.ReferenceEquals(target.ListCalculators()[0], target.GetCalculator("Foo"));
            Assert.ReferenceEquals(target.ListCalculators()[1], target.GetCalculator("SSE"));
        }

        /// <summary>
        ///A test for GetLastError
        ///</summary>
        [TestMethod()]
        public void GetLastErrorTest()
        {
            ErrorManager target = new ErrorManager(); // TODO: Initialize to an appropriate value
            Assert.AreEqual(target.ErrorHistorySize, 0);

            target.AddCalculator("SSE", new Neural.Calculators.SSEErrorCalculator());
            Dictionary<string, double> actual = new Dictionary<string, double>();
            actual["Foo"] = 0.0;

            Dictionary<string, double> expected = new Dictionary<string, double>();
            expected["Foo"] = 1.0;

            target.AccumulateError(expected, actual);
            target.ClearErrors();
            target.AccumulateError(expected, actual);

            Assert.AreEqual(0.5, target.GetLastError("SSE"), 0.001);
        }

        /// <summary>
        ///A test for GetHistoricalErrors
        ///</summary>
        [TestMethod()]
        public void GetHistoricalErrorsTest()
        {
            ErrorManager target = new ErrorManager(); // TODO: Initialize to an appropriate value
            target.AddCalculator("SSE", new Neural.Calculators.SSEErrorCalculator());
            Dictionary<System.String, double> actual = new Dictionary<System.String, double>();
            actual["Foo"] = 1.0;

            Dictionary<System.String, double> expected = new Dictionary<string, double>();
            expected["Foo"] = 0.0;

            target.AccumulateError(expected, actual);
            target.ClearErrors();
            target.AccumulateError(expected, actual);
            target.ClearErrors();

            Assert.AreEqual(2, target.GetHistoricalErrors("SSE").Count);
        }

        /// <summary>
        ///A test for GetError
        ///</summary>
        [TestMethod()]
        public void GetErrorTest()
        {
            ErrorManager target = new ErrorManager(); // TODO: Initialize to an appropriate value
            target.AddCalculator("SSE", new Neural.Calculators.SSEErrorCalculator());
            Dictionary<System.String, double> actual = new Dictionary<System.String, double>();
            actual["Foo"] = 1.0;

            Dictionary<System.String, double> expected = new Dictionary<string, double>();
            expected["Foo"] = 0.0;

            target.AccumulateError(expected, actual);
            Assert.AreEqual(0.5, target.GetError("SSE"), 0.001);

            target.ClearErrors();
            Assert.AreEqual(target.GetError("SSE"), 0.0, 0.0001);
        }

        /// <summary>
        ///A test for GetCalculator
        ///</summary>
        [TestMethod()]
        public void GetCalculatorTest()
        {
            ErrorManager target = new ErrorManager(); // TODO: Initialize to an appropriate value
            ErrorCalculator expected = new Neural.Calculators.SSEErrorCalculator(); // TODO: Initialize to an appropriate value
            target.AddCalculator(expected.DefaultName, expected);
            Assert.ReferenceEquals(target.GetCalculator("SSE"), expected);
        }

        /// <summary>
        ///A test for ClearErrors
        ///</summary>
        [TestMethod()]
        public void ClearErrorsTest()
        {
            ErrorManager target = new ErrorManager(); // TODO: Initialize to an appropriate value
            target.AddCalculator("SSE", new Neural.Calculators.SSEErrorCalculator());
            Dictionary<System.String, double> actual = new Dictionary<System.String, double>();
            actual["Foo"] = 1.0;

            Dictionary<System.String, double> expected = new Dictionary<string,double>();
            expected["Foo"] = 0.0;

            target.AccumulateError(expected, actual);
            Assert.AreEqual(0.5, target.GetError("SSE"), 0.001);

            target.ClearErrors();
            Assert.AreEqual(target.GetError("SSE"), 0.0, 0.0001);
        }

        /// <summary>
        ///A test for AddCalculator
        ///</summary>
        [TestMethod()]
        public void AddCalculatorTest()
        {
            ErrorManager target = new ErrorManager(); // TODO: Initialize to an appropriate value
            string name = "SSE"; // TODO: Initialize to an appropriate value
            ErrorCalculator calculator = new Neural.Calculators.SSEErrorCalculator(); // TODO: Initialize to an appropriate value
            target.AddCalculator(name, calculator);
            Assert.ReferenceEquals(target.GetCalculator(name), calculator);
        }

        /// <summary>
        ///A test for AccumulateError
        ///</summary>
        [TestMethod()]
        public void AccumulateErrorTest()
        {
            ErrorManager target = new ErrorManager(); // TODO: Initialize to an appropriate value
            target.AddCalculator("SSE", new Neural.Calculators.SSEErrorCalculator());
            Dictionary<string, double> expected = new Dictionary<string,double>(); // TODO: Initialize to an appropriate value
            Dictionary<string, double> actual = new Dictionary<string,double>(); // TODO: Initialize to an appropriate value

            expected["Foo"] = 1.0;
            actual["Foo"] = 0.0;

            target.AccumulateError(expected, actual);

            Assert.AreEqual(target.GetLastError("SSE"), 1.0, 0.0001);
        }

        /// <summary>
        ///A test for ErrorManager Constructor
        ///</summary>
        [TestMethod()]
        public void ErrorManagerConstructorTest()
        {
            ErrorManager target = new ErrorManager();
            Assert.AreEqual(target.Count, 0);
            Assert.AreEqual(target.ErrorHistorySize, 0);
        }
    }
}
